//app.js
import Global from './utils/global';
import regeneratorRuntime from "utils/regenerator-runtime/runtime";
App({
  onLaunch: function (options) {
    
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    this.Global = new Global;
    this.regeneratorRuntime = regeneratorRuntime;
    this.Global.initLogin();
    //授权地理位置

    this.getUserMap().then(obj => {
      
      if (obj) {
        var cs = this.Global.coordtransform.gcj02tobd09(obj.longitude, obj.latitude);
        obj.longitude = cs[0];
        obj.latitude = cs[1];
        this.globalData.userMap = obj;
        this.Global._.each(this.userMapCalllback, function (v) { v(obj); })
      } else {
        this.globalData.userMap = "用户未授权";
        console.log(this.globalData.userMap);
      }
    }, obj => {
      this.globalData.userMap = {};
      this.Global._.each(this.userMapCalllback, function (v) {
        v({});
      });
    });
  },
  getUserMap() {
    return new Promise((resolve, reject) => {
      wx.getSetting({
        success: (re) => {
          if (re.authSetting["scope.userLocation"]) {
            wx.getLocation({
              success: function (res) {
                console.log(res);
                resolve(res);
              },
              fail(res) {
                reject(res);
              }
            })
          } else {
            resolve();
          }
        }
      })
    })
  },
  globalData: {
    userInfo: null
  },
  _configCallback: [],
  _bottomCallback: [],
  nodeListCallback: [],
  loginCallback: [],
  userMapCalllback: []
})